
// var AJAX_REQUEST_URL_HEAD_PRODUCTION = "http://wallet.jiuzhouhgp.com/";
// var AJAX_REQUEST_URL_HEAD_DEV = "http://wallet.jiuzhouhgp.com/";

var AJAX_REQUEST_URL_HEAD_PRODUCTION = "http://dev-m-api.jiucaig.com/index.php?l=zh-cn&s=/Api/";
var AJAX_REQUEST_URL_HEAD_DEV = "http://dev-m-api.jiucaig.com/index.php?l=zh-cn&s=/Api/";


var TIP_SYSBUSY_ERR = "系统繁忙,请稍后再试!";
var IS_CLIENT = true;

var bf_common_view = {
	bf_win:{
		/**
		 * 初始化函数
		 * @param  {[回调函数]}
		 * @return {[无返回值]}
		 * 调用方法：init_all_ready(function(){
		 * 		alert(1);
		 * })
		 */
		init_all_ready:function(_cb){
			if (IS_CLIENT) {
				apiready = function(){
					_cb();
				}
			}
			else{

				$(function(){
					_cb();
				})
			}
		},
		/**
		 * [openWin 打开窗口]
		 * @param  {[type]} winName [窗口名称]
		 * @param  {[type]} winPath [文件路径]
		 * @param  {[type]} param   [参数]
		 * @return {[type]}         []
		 */
		openWin: function(winName,winPath,param){
			if (IS_CLIENT) {
				api.openWin({
					name: winName,
					url: winPath + winName + ".html",
					bounces: false,
					pageParam: param
				});
				return false;
			}
			else{

				if (arguments.length == 2) {
					window.location.href = DOMAIN + "/" + winPath + "/" + winName;
				}
				else{
					var lenParam = param.length;
					var params = new Array();
					for(var key in param){
						var tmp = key + "=" + param['key'];
						params.push(tmp);
					}
					params.join("&");
					window.location.href = DOMAIN + "/" + winPath + "/" + winName + "?" + params;
				}

			}

		},
		/**
		 * [closeToWin 关闭指定窗口]
		 * @param  {[type]} winName [窗口名称]
		 * @return {[type]}         []
		 */
		closeToWin: function(winName){
			api.closeToWin({
				name: winName,
			});
		},
		/**
		 * [closeWin 关闭窗口]
		 * @param  {[type]} winName [窗口名称]
		 * @return {[type]}         []
		 */
		closeWin: function(winName){
			if (winName == null || winName == undefined) {
				api.closeWin();
			}
			else{
				api.closeWin({
					name: winName
				});
			}
		},
		/**
		 * [popToast 弹出提示]
		 * @param  {[type]} msg [弹出消息]
		 * @return {[type]}     [description]
		 */
		popToast: function(msg){
			api.toast({
				msg: msg,
				duration: 2000,
				location: 'middle'
			});
		},
		popAlert: function(msg){
			api.alert({
				title: '温馨提示',
				msg:msg,
			});
		},
		popConfirm: function(msg,_cbYes,_cbNo){
			api.confirm({
				title: '温馨提示',
				msg: msg,
				buttons:['确定', '取消']
			},function(ret,err){
				if(ret.buttonIndex == 1){
					if (_cbYes) {
						_cbYes();
					};
				}
				else{
					if (_cbNo) {
						_cbNo();
					};
				}
			});
		},
	},
}
var bf_common_view = {
	bf_win:{
		/**
		 * 初始化函数
		 * @param  {[回调函数]}
		 * @return {[无返回值]}
		 * 调用方法：init_all_ready(function(){
		 * 		alert(1);
		 * })
		 */
		init_all_ready:function(_cb){
			if (IS_CLIENT) {
				apiready = function(){
					_cb();
				}
			}
			else{

				$(function(){
					_cb();
				})
			}
		},
		/**
		 * [openWin 打开窗口]
		 * @param  {[type]} winName [窗口名称]
		 * @param  {[type]} winPath [文件路径]
		 * @param  {[type]} param   [参数]
		 * @return {[type]}         []
		 */
		openWin: function(winName,winPath,param){
			if (IS_CLIENT) {
				api.openWin({
					name: winName,
					url: winPath + winName + ".html",
					bounces: false,
					pageParam: param
				});
				return false;
			}
			else{

				if (arguments.length == 2) {
					window.location.href = DOMAIN + "/" + winPath + "/" + winName;
				}
				else{
					var lenParam = param.length;
					var params = new Array();
					for(var key in param){
						var tmp = key + "=" + param['key'];
						params.push(tmp);
					}
					params.join("&");
					window.location.href = DOMAIN + "/" + winPath + "/" + winName + "?" + params;
				}

			}

		},
		/**
		 * [openWinLogin 判断用户登陆后才会打开页面]
		 * @param  {[type]} winName [窗口名称]
		 * @param  {[type]} winPath [文件路径]
		 * @param  {[type]} param   [参数]
		 * @return {[type]}         [description]
		 */
		openWinLogin: function(winName,winPath,Path,param){
			var token = bf_common_data.bf_user_info.getUserToken();
			if (token == "") {
				//popToast(TIP_LOGIN_FIRST);
				bf_common_view.bf_win.openWin('login',Path +'Login/');
				return;
			};
			api.openWin({
				name: winName,
				url: winPath + winName + ".html",
				bounces: false,
				pageParam: param
			});
			return false;
		},
		/**
		 * [closeToWin 关闭指定窗口]
		 * @param  {[type]} winName [窗口名称]
		 * @return {[type]}         []
		 */
		closeToWin: function(winName){
			api.closeToWin({
				name: winName,
			});
		},
		/**
		 * [closeWin 关闭窗口]
		 * @param  {[type]} winName [窗口名称]
		 * @return {[type]}         []
		 */
		closeWin: function(winName){
			if (winName == null || winName == undefined) {
				api.closeWin();
			}
			else{
				api.closeWin({
					name: winName
				});
			}
		},
		/**
		 * [popToast 弹出提示]
		 * @param  {[type]} msg [弹出消息]
		 * @return {[type]}     [description]
		 */
		popToast: function(msg){
			api.toast({
				msg: msg,
				duration: 2000,
				location: 'middle'
			});
		},
		popAlert: function(msg){
			api.alert({
				title: '温馨提示',
				msg:msg,
			});
		},
		popConfirm: function(msg,_cbYes,_cbNo){
			api.confirm({
				title: '温馨提示',
				msg: msg,
				buttons:['确定', '取消']
			},function(ret,err){
				if(ret.buttonIndex == 1){
					if (_cbYes) {
						_cbYes();
					};
				}
				else{
					if (_cbNo) {
						_cbNo();
					};
				}
			});
		},
	},
}
var bf_common_data = {
	bf_check:{
		/**
		 * [checkTelValid 检查手机号是否可用]
		 * @param  {[type]} telStr [手机号码]
		 * @return {[type]}        [description]
		 */
		checkTelValid: function(telStr){
			var reTel = /^1\d{10}$/;
			if (reTel.test(telStr)){
				return true;
			}
			else{
				bf_common_view.bf_win.popToast(TIP_TEL_FORMAT_ERR);
				return false;
			}
		},
		/**
		 * [checkCodeValid 检查验证码是否可用]
		 * @param  {[type]} codeStr [验证码]
		 * @return {[type]}         [description]
		 */
		checkCodeValid: function(codeStr){
			var reCode = /^\d{6}$/;
			if (!reCode.test(codeStr)) {
				bf_common_view.bf_win.popToast(TIP_CODE_FORMAT_ERR);
				return false;
			}
			else{
				return true;
			};;
			return codeStr.length > 0;
		},
		checkNameValid: function(nameStr){
			if (nameStr.length > 6 && nameStr.length <= 16) {
				return true;
			}else{
				bf_common_view.bf_win.popToast(TIP_PWD_FORMAT_ERR);
				return false;
			}
		},
	},
	bf_user_info:{
		/**
		 * [checkUserLogin 检查用户是否已经登录]
		 * @return {[type]} [description]
		 */
		checkUserLogin: function(){
			if (bf_common_data.bf_user_info.getUserToken() == "") {
				return false;
			}
			return true;
		},
		/**
		 * [setUserInfo 设置用户信息]
		 * @param {[type]} userInfo [成功 或 失败]
		 */
		setUserInfo: function(userInfo){
			return $api.setStorage('userInfo', $api.jsonToStr(userInfo));
		},
		/**
		 * [getUserToken 获取用户令牌]
		 * @return {[type]} [description]
		 */
		getUserToken: function(){
			var userInfo = bf_common_data.bf_user_info.getUserInfo();
			if (userInfo === false) {
				return '';
			};
			if (userInfo['data']['userInfo']['User'] == undefined) {
				return '';
			};
			return userInfo['data']['userInfo']['User']['token'];
		},
		/**
		 * [clearAllInfo 清除本地信息]
		 * @return {[type]} [description]
		 */
		clearAllInfo: function(){
			$api.clearStorage();
		},
		/**
		 * [clearUserInfo 清除用户信息]
		 * @return {[type]} [description]
		 */
		clearUserInfo: function(){
			$api.rmStorage('userInfo');
		},
		/**
		 * [getUserField 按照字段查询 userInfo数据]
		 * @param  {[type]} field [字段名称]
		 * @return {[type]}       [description]
		 */
		getUserField: function(field){
			var userInfo = bf_common_data.bf_user_info.getUserInfo();
			if (userInfo === false) {
				return false;
			}
			return userInfo['data']['userInfo']['User'][field];
		},
		/**
		 * [getUserInfo 查询用户信息]
		 * @return {[type]} [用户信息]
		 */
		getUserInfo: function(){
			var userInfo = $api.getStorage('userInfo');
			if (userInfo == undefined) {
				return false;
			}
			return $api.strToJson(userInfo);
		},
		/**
		 * [refreshUserInfo 刷新本地用户数据]
		 * @return {[type]} [不做错误提示]
		 */
		refreshUserInfo: function(url,cb){
			var token = bf_common_data.bf_user_info.getUserToken();
			var data = {
				values:{
					token:token
				}
			};
			bf_common_ctrl.ctrl_event.ajaxReq(url,data,function(ret){
				switch(ret['code']){
					case 0:{
						bf_common_data.bf_user_info.setUserInfo(ret);
						cb();
						break;
					}
					default:{

						break;
					}
				}
			});
		},
	},
	bf_html:{
		/**
		 * [getValById 按照 ID 查询值]
		 * @param  {[type]} id [id]
		 * @return {[type]}    [description]
		 */
		getValById: function(id){
			var obj = $api.byId(id);
			return $api.val(obj);
		},
		/**
		 * [setValById 按照 id 设置值]
		 * @param {[type]} id  [id]
		 * @param {[type]} val [值]
		 */
		setValById: function(id,val){
			var obj = $api.byId(id);
			return $api.val(obj, val);
		},
		/**
		 * [getTextById 按照 id查文本]
		 * @param  {[type]} id [id]
		 * @return {[type]}    [description]
		 */
		getTextById: function(id){
			var obj = $api.byId(id);
			return $api.text(obj);
		},
		/**
		 * [getHtmlById 按照id查 html]
		 * @param  {[type]} id [id]
		 * @return {[type]}    [description]
		 */
		getHtmlById: function(id){
			var obj = $api.byId(id);
			return $api.html(obj);
		},
		/**
		 * [setTextById 按照id设置文本]
		 * @param {[type]} id   [id]
		 * @param {[type]} text [文本]
		 */
		setTextById: function(id, text){
			var obj = $api.byId(id);
			return $api.text(obj, text);
		},
		/**
		 * [setHtmlById 按照 ID 设置 html]
		 * @param {[type]} id   [id]
		 * @param {[type]} html [html]
		 */
		setHtmlById: function(id, html){
			var obj = $api.byId(id);
			return $api.html(obj, html);
		},
		/**
		 * [appendHtmlById 按照 ID 设置 html]
		 * @param {[type]} id   [id]
		 * @param {[type]} html [html]
		 */
		appendHtmlById: function(id, html){
			var obj = $api.byId(id);
			return $api.append(obj, html);
		},
		/**
		 * [setAttrById 按照id设置attr属性]
		 * @param {[type]} id   [id]
		 * @param {[type]} attr [attr]
		 * @param {[type]} val  [val]
		 */
		setAttrById: function(id, name, val){
			var obj = $api.byId(id);
			$api.attr(obj, name, val);
		},
		getAttrById: function(id, name){
			var obj = $api.byId(id);
			return $api.attr(obj, name);
		},
		/**
		 * [removeClsById 按照id删除class属性]
		 * @param  {[type]} id  [id]
		 * @param  {[type]} cls [class]
		 * @return {[type]}     [description]
		 */
		removeClsById: function(id, cls){
			var obj = $api.byId(id);
			$api.removeCls(obj, cls);
		},
		/**
		 * [addClsById 按照id添加class属性]
		 * @param {[type]} id  [description]
		 * @param {[type]} cls [description]
		 */
		addClsById: function(id,cls){
			var obj = $api.byId(id);
			$api.addCls(obj, cls);
		},
		/**
		 * [addCssById 按照id添加css]
		 * @param {[type]} id  [description]
		 * @param {[type]} css [description]
		 */
		addCssById: function(id,css){
			var obj = $api.byId(id);
			$api.css(obj, css);
		},
		/**
		 * [getCssById 按照id获取css]
		 * @param  {[type]} id   [description]
		 * @param  {[type]} prop [description]
		 * @return {[type]}      [description]
		 */
		getCssById: function(id,prop){
			var obj = $api.byId(id);
			$api.cssVal(obj, prop);
		},
		/**
		 * [focusById 按照id设置焦点]
		 * @param  {[type]} id [id]
		 * @return {[type]}    [description]
		 */

		focusById: function(id){
			setTimeout("$api.byId('" + id + "').focus();",600);
		},
		/**
		 * [blurById 按照id取消焦点]
		 * @param  {[type]} id [description]
		 * @return {[type]}    [description]
		 */
		blurById: function(id){
			setTimeout("$api.byId('" + id + "').blur();",600);
		},
	}
}
var bf_common_ctrl = {
	ctrl_event:{
		/**
		 * [ajaxReq ajax请求]
		 * @param  {[type]} url  [url链接]
		 * @param  {[type]} data [传递的数据]
		 * @param  {[type]} _cb  [回调函数]
		 * @return {[type]}      [description]
		 */
		ajaxReq: function(url, data, _cb, debug){
			if (IS_CLIENT) {
				var netType = api.connectionType;
				// connectionType != 'wifi' && connectionType != '3g' && connectionType != '4g' && connectionType != '2g'
				if (netType == 'none') {
					_cb(bf_cache.download.get_download_cache(url));
					return;
				};
				// width = 4;
				// showPro();

				api.showProgress({
				    title: '',
				    text: '',
				    modal: true
				});
				api.ajax({
					url: DOMAIN + url,
					method: 'post',
					timeout: 30,
					dataType: 'json',
					contentType: 'application/json',
					// returnAll:false,
					data:data,
				},function(ret,err){
					setTimeout(function(){
						api.hideProgress();
					},50);
					if (debug) {
						api.alert({
							title:"温馨提示",
							msg:ret
						});
						hidePro();
					}
					if (ret) {
						_cb(ret,data);
						hidePro();
					} else {
						api.alert({
							title:"温馨提示",
							msg:('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode + "|" + url + "params=" + $api.jsonToStr(data))
						});
						hidePro();
					};
				});
			}
			else{
				$.post(DOMAIN + url, data['values'], _cb);
			}
		},
		/**
		 * [execScript 执行指定窗口脚本]
		 * @param  {[type]} funcName  [执行函数名称]
		 * @param  {[type]} winName   [窗口名称]
		 * @param  {[type]} frameName [frame 名称]
		 * @return {[type]}           [description]
		 */
		execScript: function(funcName, winName,frameName){
			var data = {
				name:winName,
				script:funcName,
			}
			if (arguments.length == 3) {
				data['frameName'] = frameName;
			}
			api.execScript(data);
		},
		/**
		 * [getPicture 从相册打开选择图片]
		 * @param  {[type]} width  [图片宽度]
		 * @param  {[type]} height [图片高度]
		 * @param  {[type]} _cb    [回调函数]
		 * @return {[type]}        [description]
		 */
		getPicture: function(_cb, type, saveToPhotoAlbumType, width, height, data){
			var options = {
				sourceType: type,
				allowEdit: true,
				quality: 80,
				saveToPhotoAlbum: saveToPhotoAlbumType
			};

			if (arguments.length == 3) {
				options['targetWidth'] = width;
				options['targetHeight'] = height;
			};
			api.getPicture(options, function(ret, err){
				if (ret) {
					if (ret.data != "") {
						api.showProgress({
							title: '图片上传中...',
							modal: false
						});
						_cb(ret,data);
					}
				} else{
					//popToast($api.jsonToStr(err));
				}
			});
		},
		/**
		 * [refreshHeader 下拉头部刷新,请再回调函数调用refreshHeaderLoadDone结束刷新]
		 * @param  {[type]} img       [刷新时展示的图片,使用widget协议]
		 * @param  {[type]} bgColor   [背景颜色]
		 * @param  {[type]} textColor [文本颜色]
		 * @param  {[type]} _cb       [回调函数]
		 * @return {[type]}           [description]
		 */
		refreshHeader: function(img,bgColor,textColor,_cb){
			api.setRefreshHeaderInfo({
					visible: true,
					loadingImg: img,
					bgColor: bgColor,
					textColor: textColor,
					textDown: '下拉刷新...',
					textUp: '松开刷新...',
					showTime: true
				},
				function(ret, err){
					_cb(ret,err);
				}
			);

		},
		/**
		 * [addEventById 为指定 ID 的元素添加事件]
		 * @param {[type]} id   [description]
		 * @param {[type]} type [description]
		 * @param {[type]} _cb  [description]
		 */
		addEventById: function(id,type,_cb){
			var obj = $api.byId(id);
			$api.addEvt(obj, type, _cb);
		},
		/**
		 * [removeEventById 为指定 ID 的元素移除事件]
		 * @param {[type]} id   [description]
		 * @param {[type]} type [description]
		 * @param {[type]} _cb  [description]
		 */
		removeEventById: function(id,type,_cb){
			var obj = $api.byId(id);
			$api.rmEvt(obj, type, _cb);
		},
		/**
		 * [bf_set_clipBoard 设置剪切板内容]
		 * @param  {[type]} value   [description]
		 * @param  {[type]} _cb       [description]
		 * @return {[type]}           [description]
		 */
		bf_set_clipBoard: function(value,_cb){
			var obj = api.require('clipBoard');
			var value = value;
			obj.set({
				value: value
			}, function(ret, err){
				if(ret.status){
					_cb(ret,err);
				}else{
					api.alert({msg:err.msg});
				}
			});
		},
		/**
		 * [bf_get_clipBoard 获取剪切板中的数据]
		 * @return {[type]}           [description]
		 */
		bf_get_clipBoard: function(){
			var obj = api.require('clipBoard');
			obj.get( function(ret, err){
				if(ret.status){
					api.alert(ret['vlaue']);
				}else{
					api.alert({msg:err.msg});
				}
			});
		},
		initComment: function(id){
			bf_common_ctrl.ctrl_event.addEventById(id,'focus',function(event){
				addClsById(id,'comment-input-follow');
				event.preventDefault();
			})
			bf_common_ctrl.ctrl_event.addEventById(id,'blur',function(event){
				removeClsById(id,'comment-input-follow');
				event.preventDefault();
			})
		},
		/**
		 * [bf_get_clipBoard 获取剪切板中的数据]
		 * @return {[type]}           [description]
		 */
		bf_call: function(tel){
			api.call({
				type: 'tel_prompt',
				number: tel
			});
		},
	},
	ctrl_func:{
		save_url_to_album:function(url,msg){
			api.download({
				url:url,
			},function(ret,err){
				if (ret.state == 1) {
					//保存到相册
					ret.savePath
					api.saveMediaToAlbum({
					    path: ret.savePath
					}, function(ret, err) {
					    if (ret) {
					    	bf_common_view.bf_win.popToast(msg);
					    } else {
                    		bf_common_view.bf_win.popToast('保存失败');
					    }
					});
				}
				else{
                    bf_common_view.bf_win.popToast('保存失败');
				}
			})
		},
		net_detect:function(cb){

			//unknown            //未知
			//ethernet        //以太网
			//wifi            //wifi
			//2g                //2G网络
			//3g                //3G网络
			//4g                //4G网络
			//none            //无网络
	        api.addEventListener({
	                name:'offline'
	            },function(ret,err){
	            	if (ret.connectionType == undefined) {
	            		ret.connectionType = 'none';
	            	}
	            	cb(ret.connectionType);
	        });
	        api.addEventListener({
	                name:'online'
	            },function(ret,err){
	            	cb(ret.connectionType);
	        });
		},
		/**
		 * [getNowTime 获取当前时间]
		 * @param  {[type]} id [description]
		 * @return {[type]}    [description]
		 */
		getNowTime:function(){
			var now = new Date();
			var year = now.getFullYear();
			var month = now.getMonth()+1;
			var date = now.getDate();
			var hour = now.getHours();
			var minute = now.getMinutes();
			var second = now.getSeconds();
			var time_content = year+"-"+bf_common_ctrl.ctrl_func.changeTime(month)+"-"+bf_common_ctrl.ctrl_func.changeTime(date)+" "+bf_common_ctrl.ctrl_func.changeTime(hour)+":"+bf_common_ctrl.ctrl_func.changeTime(minute);
			return time_content;
		},
		changeTime:function(str){
			var str = parseInt(str);
			if(str < 10){
				return str = '0'+str;
			}
			return str;
		}
	}
}

// 修改日期为时间戳
var change_time_stamp = function(time){
	var date=new Date();
	date.setFullYear(time.substring(0,4));
	date.setMonth(time.substring(5,7)-1);
	date.setDate(time.substring(8,10));
	date.setHours(time.substring(11,13));
	date.setMinutes(time.substring(14,16));
	date.setSeconds(time.substring(17,19));
	return Date.parse(date)/1000;
}

var openNoFile = function(){
	bf_common_view.bf_win.popToast('此功能尚未开放');
}

// (function(window){
	var s = {};

	var AJAX_REQUEST_TYPE_PRODUCTION = 1,
		AJAX_REQUEST_TYPE_DEV = 2;



	var AJAX_PARAMETER = {
		headers:{
			'Accept-Language':'zh-CN',
			'Content-Type':'application/json'
		},
		method : 'get',
		cache : true,
		timeout : 60,
		dataType : 'json',
		returnAll : false,
		requestType:AJAX_REQUEST_TYPE_DEV,
		data : {}
	};
	/**
	 * 基于apicloud ajax二次封装
	 *
	 * @param {Object} param
	 */
	s.ajax = function(param){
		var connectionType = api.connectionType;
		if('none' == connectionType){
			bf_common_view.bf_win.popToast("当前无网络连接");
			return;
		}
		//获取ajax请求默认配置
		// var data = s.jsonCopy(AJAX_PARAMETER);
		var data = AJAX_PARAMETER;
		if(param.hasOwnProperty("requestType")){
			data['requestType'] = param['requestType'];
		}
		if(param.need_login){
			var tokenData = $api.getStorage('tokenData');
			if ($c.isEmpty(tokenData)) {
				data['headers']['Authorization'] = "SK" + " " + tokenData.session_key;
			}
			// var loginInfo = api.getPrefs({
			//     sync: true,
			//     key: 'login_info'
			// });
			// if($c.isEmpty(loginInfo)){
			// 	loginInfo = $api.strToJson(loginInfo);
			// 	data['headers']['Authorization'] = "Bearer " + loginInfo.token;
			// }
		}

		if(param.noContentType){
			delete data['headers']['Content-Type'];
		}

		if(param.hasOwnProperty("values")){
			data['data']['body'] = param['values'];
		}

		if(!param.hasOwnProperty("url")){
			$c.toast({msg:'url not found！'});
			return;
		}

		//判断是否有上传文件
		if(param.hasOwnProperty("files")){
			data['data']['files'] = param['files'];
		}
		//判断是否配置请求类型
		if(param.hasOwnProperty("method")){
			data['method'] = param['method'];
		}

		//判断是否配置tag
		if(param.hasOwnProperty("tag")){
			data['tag'] = param['tag'];
		}

		//判断是否配置返回数据类型
		if(param.hasOwnProperty("dataType")){
			data['dataType'] = param['dataType'];
		}

		//判断是否缓存
		if(!param.hasOwnProperty("cache")){
			param.cache = false;
		}

		//是否显示进度条
		if(!param.loading_hide){
	//			this.Loading(0);
		}

		if(!param.url){
			return console.warn("url 不能为空！");
		}

		if(param.url.indexOf('http') < 0){
			switch (data.requestType){
				case AJAX_REQUEST_TYPE_DEV:
					data['url'] = AJAX_REQUEST_URL_HEAD_DEV;
					break;
				default:
					data['url'] = AJAX_REQUEST_URL_HEAD_PRODUCTION;
					break;
			}
			data['url'] += param.url;
		}else{
			data['url'] = param.url;
		}
		 console.log(JSON.stringify(data));
		api.ajax(data, function(ret, err) {
			console.log(JSON.stringify(ret) + "返回");
		    if(ret){
		    	if(401 == ret.status){
		    		bf_common_view.bf_win.popToast("登录过期");
		    		api.setPrefs({
					    key: 'login_info',
					    value: ''
					});

					api.setPrefs({
						key: 'user_info',
						value: ''
					});

					api.sendEvent({name:'my'});
					api.openWin({
					    name: 'login',
					    url: 'widget://html/my/login.html',
					    pageParam: {
					        name: 'test'
					    }
					});
		    		return;
		    	}
		    	param.success(ret);
		    } else {
		    	//bf_common_view.bf_win.popToast("系统错误,请稍候再试!");
	    		// $c.Loading(-1);
	    		// $c.Log('err:' + JSON.stringify(err));
		    	if(param.err){
		    		param.err(err);
		    	}
		    }
		});
	};

	/**
	 * @brief		json数据追加
	 *
	 * @param{Object}	dest	目标json
	 * @param{Object}	src		追加的json数据
	 */
	s.jsonCopy = function(src){
		var dest = {};
		if(src instanceof Array){
			dest = [];
		}
		for (var key in src) {
		    var val = src[key];
		    dest[key] = typeof val === 'object' ? arguments.callee(val) : val;
		}
		return dest;
	};
	/**
	 * @brief		判断是否是空
	 *
	 * @param{Object}	value	对象
	 */
	s.isEmpty = function isEmpty(value)
	{
		if (value == null || value == "" || value == "undefined" || value == undefined || value == "null" || value == "(null)" || value == 'NULL' || typeof (value) == 'undefined')
		{
			return false;
		} else
		{
			value = value + "";
			value = value.replace(/\s/g, "");
			if (value == "")
			{
				return false;
			}
			return true;
		}
	};
	/**
	 * 判断数组是否包含元素
	 *
	 * @param {Object} arr
	 * @param {Object} needle
	 */
	s.inArray = function(arr, needle){
		if(!$api.isArray(arr)){
			console.warn('请输入数组！');
			return;
		}
		var isContain = -1;
		for(var i = 0,len = arr.length;i < len;i++){
			if(arr[i] == needle){
				isContain = i;
			}
		}
		return isContain;
	};
	/**
	 * 格式化时间
	 *
	 *
	 */
	s.formatDate = function(time, fmt) {
		time = new Date(time);
		fmt = fmt?fmt:'yyyy-MM-dd';
		var o = {
			"M+": time.getMonth() + 1, //月份
			"d+": time.getDate(), //日
			"h+": time.getHours(), //小时
			"m+": time.getMinutes(), //分
			"s+": time.getSeconds(), //秒
			"q+": Math.floor((time.getMonth() + 3) / 3), //季度
			"S": time.getMilliseconds() //毫秒
		};
		if(/(y+)/.test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (time.getFullYear() + "").substr(4 - RegExp.$1.length));
		}
		for(var k in o) {
			if(new RegExp("(" + k + ")").test(fmt)) {
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			}
		}
		return fmt;
	};
	/**
	 * 打开滚动选择框
	 *
	 * @param {Object} param
	 * @param {Object} callback
	 */
	s.openScrollSelector = function(param, callback){
		if(window.isOpenPop){
			return;
		}
		window.isOpenPop = true;
		api.addEventListener({
			name: "POPWINDOW_ACTION_LISTENER"
		}, function(ret) {
			window.isOpenPop = false;
			api.removeEventListener({
				name: 'POPWINDOW_ACTION_LISTENER'
			});
			if(ret.value.index < 0) {
				return;
			}
			if(callback){
				callback(ret.value);
			}
		});
		api.openFrame({
			name: "scrollSelector",
			url: 'widget://html/scrollSelector.html',
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			},
			bounces: false,
			bgColor: 'rgba(0,0,0,0.2)',
			pageParam:param
		});
	};
	window.$c = s;
// })(window);
